package com.hspedu.Map_;

import java.util.*;

public class MapMethod {
    public static void main(String[] args) {
        //演示map接口常用方法
        HashMap map = new HashMap();
        map.put("邓超","孙俪");
        map.put("王宝强","马蓉");
        map.put("宋喆","马蓉");
        map.put("刘令博",null);
        map.put(null,"刘亦菲");
        map.put("鹿晗","关晓彤");

        //第一组：先取出 所有的key 通过key获取对应的value
        Set keySet = map.keySet();
        System.out.println("keySet"+keySet);
        //增强for
        System.out.println("==================");
        for (Object o : keySet) {
            System.out.println(o+"-"+map.get(o));
        }

        //迭代器
        System.out.println("===============");
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()){
            Object key = iterator.next();
            System.out.println("iterator-"+map.get(key));
        }

        System.out.println("==============");
        //吧所有的values取出来
        Collection values = map.values();
        System.out.println(values);



        //通过entrySet() 来获取 k-v
        System.out.println("============");
        Set entrySet = map.entrySet();
        for (Object entry : entrySet) {
            Map.Entry m=(Map.Entry)entry;
            System.out.println(m.getKey()+"-"+m.getValue());
        }
    }
}
